﻿Public Class xtf_LISTADOconfig_modulo_

    Public Overrides Sub IniciarLista()
        Try
            gdc_general.BeginUpdate()
            gdc_general.DataSource = dtt_DataTable
            'ulg_Lista.DisplayLayout.GroupByBox.Style = Infragistics.Win.UltraWinGrid.GroupByBoxStyle.Full

            'Creacion y carga de Cuentas
            dtt_DataTable.Columns.Add("Codigo")
            dtt_DataTable.Columns.Add("Grupo")
            dtt_DataTable.Columns.Add("Modulo")
            dtt_DataTable.Columns.Add("Visible")
            dtt_DataTable.Columns.Add("Root")

            gdv_general.PopulateColumns(dtt_DataTable)

            Dim obj_config_modulo_ As New cls_config_modulo_
            If obj_config_modulo_.CargarTodos Then
                For Each config_modulo As cls_config_modulo_ In obj_config_modulo_.Items
                    AgregarItem(config_modulo)
                Next
            End If
            'ulg_Lista.DataBind()

            FiltrarColumnas()
            gdc_general.EndUpdate()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Function AgregarItem(ByRef config_modulo As cls_config_modulo_) As DataRow
        Try
            Dim Row As DataRow = dtt_DataTable.NewRow

            Row("Codigo") = config_modulo.idmodulo
            Row("Grupo") = config_modulo.modulo.grupo
            Row("Modulo") = config_modulo.modulo.subgrupo
            If config_modulo.activo Then
                Row("Visible") = "Si"
            Else
                Row("Visible") = "No"
            End If

            If config_modulo.modulo.esroot Then
                Row("Root") = "Si"
            Else
                Row("Root") = "No"
            End If

            dtt_DataTable.Rows.Add(Row)
            'ulg_Lista.Rows(ulg_Lista.Rows.Count - 1).Height = 19
            Return Row
        Catch ex As Exception

        End Try

    End Function

    Public Sub ModificarItem(ByRef config_modulo As cls_config_modulo_, ByRef ulg_row As DataRow)
        ulg_row("Codigo") = config_modulo.idmodulo
        ulg_row("Grupo") = config_modulo.modulo.grupo
        ulg_row("Modulo") = config_modulo.modulo.subgrupo
        If config_modulo.activo Then
            ulg_row("Visible") = "Si"
        Else
            ulg_row("Visible") = "No"
        End If
        If config_modulo.modulo.esroot Then
            ulg_row("Root") = "Si"
        Else
            ulg_row("Root") = "No"
        End If

    End Sub

    Public Overrides Sub bbi_Modificar_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs)
        If ComprobarPermiso(PERMISOModificar) Then
            Try
                Dim barrio As Object 'New cls_barrio_
                barrio = New cls_config_modulo_
                If gdv_general.SelectedRowsCount > 0 Then
                    If barrio.Buscar(gdv_general.GetDataRow(gdv_general.GetSelectedRows(0))("Codigo")) Then
                        bsi_estado.Caption = "Cargando..."
                        Application.DoEvents()
                        Dim ABM As Object 'New xtf_ABMbarrio
                        ABM = New xtf_ABMconfig_modulo
                        ABM.Modificar(barrio, Me, gdv_general.GetDataRow(gdv_general.GetSelectedRows(0)))
                        ABM.ControlarModificaciones(ABM.lac_general.items)
                        bsi_estado.Caption = "Listo"
                    End If
                End If

            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub


    Public Sub New()

        Me.Cursor = Cursors.WaitCursor
        InitializeComponent()
        bbi_Nuevo.Enabled = False
        bbi_eliminar.Enabled = False
        PERMISONuevo = ""
        PERMISOModificar = ""
        PERMISOEliminar = ""
        PERMISOImprimir = ""
        Me.Text = lbl_modulo.Text : lbl_modulodescripcion.Text = "Listado de " & lbl_modulo.Text & "."
        IniciarLista()
        Me.Cursor = Cursors.Default

    End Sub

End Class